package org.bemo.controller;

import javax.xml.bind.annotation.XmlRootElement;

import org.bemo.utils.JXUtils;
import org.springframework.web.bind.annotation.ResponseBody;

import com.blade.mvc.annotation.Controller;
import com.blade.mvc.annotation.JSON;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.QueryParam;
import com.blade.mvc.annotation.Route;
import com.blade.mvc.http.HttpMethod;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;

import net.sf.json.JSONObject;

@Controller
public class JieXiController {
	
	@Route(value="/get",method = HttpMethod.POST)
	@JSON
	public String get(@QueryParam String videoUrl){
		//获取视频对象地址
		try {
			String vkey = JXUtils.getVkey(videoUrl);
			return vkey;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Route(value="/play",method = HttpMethod.POST)
	@JSON
	public JSONObject play(@QueryParam String vkey){
		//获取视频对象地址
		try {
			JSONObject jsonObject = JXUtils.getJson(vkey);
			//解析
			return jsonObject;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Route("/api")
	public String index(){
		return "jiexi/index";
	}
	
	
	//获取XML
	@Route("/getXml")
	public void getXml(@QueryParam String vkey,Response response){
		try {
			String xml =  JXUtils.getXml(vkey);
			System.out.println(xml);
			response.xml(xml);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	@Route("/test")
	public String test(@QueryParam String url,Request req){
		req.attribute("url",url);
		return "ckplayer/demo3";
	}
	
}
